

#ifndef NACSTATIONDB_H_
#define NACSTATIONDB_H_

#include <stdio.h>
#include <stdint.h>
#include <pthread.h>

#include "log.h"

struct server_config_t {

    char radiusd_ip[32];
    char secret[32];
    char server[32];
    int http_port;
    int mqtt_port;
    
    char mqtt_username[32];
    char mqtt_passwd[32];
    char db_server[32];
    int db_port;
    char db_name[32];
    char db_user[32];
    char db_passwd[32];
};




int find_session(char* username, char* session_id, char* nasip);

#define ETH_ALEN 6

#define USER_STATE_INIT  0  // 未认证用户
#define USER_STATE_AUTH  1 // 正在认证的用户
#define USER_STATE_OK    2  // 认证成功的用户
#define USER_STATE_LOCK  3  // 超额用户
#define USER_STATE_WAIT  4
#define USER_STATE_FREE  5 // 白名单用户

#define USER_AUTH_TYPE_MAC   4 // MAC 无感知认证的用户
#define USER_AUTH_TYPE_PORTAL 5  // portal 认证的用户

typedef struct {
    uint8_t mac[6];
    uint16_t wlanX;
    uint32_t ip;
    uint32_t sn;
    uint32_t status;
    uint32_t authtype;
    uint32_t prt_proto;
    int32_t inspeed;
    int32_t outspeed;
    uint32_t session_time;
    int32_t quota_bytes;
    int32_t quota_gigas;
    uint32_t online_time;
    uint64_t inbytes;
    uint64_t inpackets;
    uint64_t outbytes;
    uint64_t outpackets;
    uint32_t name_len;
    char user_name[64];
    char acct_session_id[128];
} db_sta_t;




//pthread_mutex_t G_userlock;
//
//static inline int nac_user_lock(void)
//{
//	return pthread_mutex_lock(&G_userlock);
//}
//
//static inline int nac_user_unlock(void)
//{
//	return pthread_mutex_unlock(&G_userlock);
//}
int regist_dev(const char* mac, const char* nasip, const char* secret,const char* pubkey);
int login_dev(const char* mac, const char* nasip, const char* secret);
 int update_acu(char* mac, const char* nasip, const char* pubkey);
 int delete_finished_session();
#endif
